package pack.be;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class BEAndroidActivity extends Activity {
	
	private Button connectButton;
	private EditText customerCodeEditTxt;
	private EditText passwordEditTxt;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        customerCodeEditTxt = (EditText)findViewById(R.id.customerCode);
        passwordEditTxt = (EditText)findViewById(R.id.passwordCustomer);
        connectButton = (Button)findViewById(R.id.connectBut);
        
        connectButton.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View arg0) {
				
				//if the editbox are empty
				if((customerCodeEditTxt.getText().length() == 0) || (passwordEditTxt.getText().length() == 0) ){
					//Show a pop up to notice that user doesn't filled the user's info
			        Toast t = Toast.makeText(getApplicationContext(), "Please, complete your informations", Toast.LENGTH_LONG);
			        t.setGravity(Gravity.CENTER, 0, 0);
			        t.show();
				}else{
					ConnectionPostgre con = new ConnectionPostgre();
					con.setUsername(String.valueOf(customerCodeEditTxt.getText()));
					Intent intent = new Intent(BEAndroidActivity.this, ProjectListView.class);
					startActivity(intent);
				}
				
				//if cusomerCode and password are correct then we change the view
				//if(customerCodeEditTxt.getText() == /*code from bdd*/ && passwordEditTxt.getText() == /*pwd from bdd*/ ){
					/*Intent intent = new Intent(BEAndroidActivity.this, ProjectListView.class);
					startActivity(intent);
				}
				else{
					//display popup to say try again error connection
				}*/	
				
			}
		});
        
        
        
    }
    
    public EditText getCustomerCodeEditTxt() {
		return customerCodeEditTxt;
	}

	public void setCustomerCodeEditTxt(EditText customerCodeEditTxt) {
		this.customerCodeEditTxt = customerCodeEditTxt;
	}
}